<%-- 
    Document   : findReservedTickets
    Created on : Dec 19, 2012, 1:29:59 PM
    Author     : alexxxey
--%>

<%@page import="java.util.List"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Booking Tickets Web Appliaction</title>
    </head>
    <body>
        <%@page import="javax.naming.*, bookingtickets.*" %>        
        <%!
            BookingTicketsSessionRemote ejbRef = null;               
        %>
        <%
            InitialContext ic = new InitialContext();
            ejbRef = (BookingTicketsSessionRemote)ic.lookup("bookingtickets.BookingTicketsSessionRemote");
        %>
                
        <form method="POST">
            <h3>Поиск по номеру паспорта</h3>
            <p>Номер паспорта <input type="text" name="pasportNum"></p>
            <input type="submit" value="Поиск">
        </form>
        
        <%
            if (request.getParameter("pasportNum") != null)
            {
                try
                {                                    
                    int pasport = new Integer(
                            new String(request.getParameter("pasportNum").getBytes("ISO-8859-1")));

                    List<Ticket> ticketList = ejbRef.reservedTickets(pasport);

                    %><h3>Зарезервированные билеты</h3><%

                    if (ticketList != null && ticketList.size()!=0)
                    {%>  
                        <form action="doCancelReserve.jsp" method="POST">
                            <table BORDER=2>
                                <tr>
                                    <td align=center> </td>
                                    <td align=center>Место</td>                
                                    <td align=center>Маршрут</td>
                                    <td align=center>Имя</td>
                                    <td align=center>Фамилия</td>                                    
                                    <td align=center>Паспорт</td>                                    
                                </tr>                                                            
                        <% 
                            for (int i=0; i<ticketList.size(); ++i)
                            {
                                Ticket t = ticketList.get(i);                                
                                String place = new Integer(t.getTicketPK().getPlace()).toString();
                                String trip = new Integer(t.getTicketPK().getTripid()).toString();
                                String pkStr = place + "," + trip;
                                String pasportStr = new Integer(pasport).toString();
                                String firstName = t.getFirstname();
                                String lastName = t.getLastname();

                                %> 
                                <tr>
                                    <td align=center> 
                                        <input type="checkbox" name="tickets" value=<%= pkStr%>> 
                                    </td>
                                    <td align=center> <%= place%></td>
                                    <td align=center> <%= trip%></td>
                                    <td align=center> <%= firstName%></td>
                                    <td align=center> <%= lastName%></td>
                                    <td align=center> <%= pasportStr%></td>
                                </tr>  

                                <%
                            }%>
                            </table>  
                            
                            <input type="submit" value="Отменить резервирование">
                            
                        </form>                            
                    <%
                    }
                    else
                    {
                        %><h3>Ничего не найдено!</h3><%
                    }
                }
                catch (NumberFormatException e)
                {
                    %><h3>Параметры поиска введены неправильно!</h3><%
                }
            }            
        %>
        
        <p><a href="index.jsp">Главная страница</a></p>
    </body>
</html>
